home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / edit / jed207.lha / src / jed.lha / command.h < prev    next >
C/C++ Source or Header  |  1993-01-06  |  3KB  |  119 lines

  1.  
  2. /*
  3.  * COMMAND.H
  4.  * (c) 1992-3 J.Harper
  5.  */
  6.  
  7. #ifndef _COMMAND_H
  8. #define _COMMAND_H
  9.  
  10. #include <hash.h>
  11.  
  12. #define MIN_STACK       2048
  13. #define MAX_CS_RECURSE       128
  14. #define COMMENT_CHAR       ';'
  15. #define GSYMTABSIZE       256
  16.  
  17. #define findgsym(s)       ((GSYM *)findhash(SymbolTab, s, GSYMTABSIZE))
  18.  
  19. /* command function */
  20. typedef struct VALUE *(*CMPTR)(LONG, struct VALUE *);
  21.  
  22. /*
  23.  * This structure is the base of all argument/result communication between
  24.  * commands.
  25.  */
  26. typedef struct VALUE {
  27.     union {
  28.     STRPTR        String;
  29.     LONG        Number;
  30.     CMPTR        Func;
  31.     VOID           *Generic;       /* use to init either */
  32.     }            val_Value;
  33.     BYTE        val_Type;
  34. } VALUE;
  35.  
  36. /* defines for val_Type */
  37. #define VTF_NONE    0    /* no value! */
  38. #define VTF_ANY        VTF_NONE    /* synonym for template checking */
  39. #define VTF_STRING  1    /* AllocVec()'ed string */
  40. #define VTF_NUMBER  2    /* LONG value */
  41. #define VTF_FUNC    3    /* CMPTR function */
  42.  
  43. #define VTF_BREAK   4    /* signifies that we broke out of the last string */
  44.             /* not a value - only ever found in result of the */
  45.             /* (break) command. (bit of a hack really).      */
  46.             /* The number of strings to break from is put into*/
  47.             /* val_Value.Number                  */
  48.  
  49. /*
  50.  * Each symbol is like this with a node on the front
  51.  */
  52. typedef struct {
  53.     BYTE        sym_Type;
  54.     VALUE        sym_Value;
  55. } SYM;
  56.  
  57. /* defines for sym_SymType */
  58. #define STF_COMMAND  1    /* command (or macro) to execute */
  59. #define STF_VARIABLE 2    /* variable (can be a function) */
  60.  
  61. /*
  62.  * global symbol
  63.  */
  64. typedef struct {
  65.     HASHNODE        gs_Node;
  66.     SYM            gs_Sym;
  67. } GSYM;
  68.  
  69. /*
  70.  * local symbol
  71.  */
  72. typedef struct {
  73.     struct Node        ls_Node;
  74.     SYM            ls_Sym;
  75. } LSYM;
  76.  
  77. /*
  78.  * context structure for each command string that is resolved
  79.  * it didn't seem wise to use hash tables for local variables(?)
  80.  */
  81. typedef struct {
  82.     BOOL        cs_Args;
  83.     LONG        cs_Argc;
  84.     VALUE       *cs_Argv;
  85.     struct List        cs_Locals;
  86. } CS;
  87.  
  88. /*
  89.  * Macros for checking command templates
  90.  *
  91.  * they are used at the start of a command's function, they return TRUE
  92.  * if the template was satisfied.
  93.  *
  94.  * ie,
  95.  *  if(TPLATE2(VTF_STRING, VTF_NUMBER))
  96.  */
  97. #define TPLATE1(a)     templatecmd(argc, argv, a)
  98. #define TPLATE2(a,b)     templatecmd(argc, argv, a | (b << 2))
  99. #define TPLATE3(a,b,c)     templatecmd(argc, argv, a | (b << 2) | (c << 4))
  100. #define TPLATE4(a,b,c,d) templatecmd(argc, argv, a | (b << 2) | (c << 4) | (d << 6))
  101.  
  102. /*
  103.  * how to get args, ie, (ARG1.val_Value.String)
  104.  */
  105. #define RES    argv[0]
  106. #define ARG1   argv[1]
  107. #define ARG2   argv[2]
  108. #define ARG3   argv[3]
  109. #define ARG4   argv[4]
  110. #define ARG(x) argv[x]
  111.  
  112. /*
  113.  * how to return stuff (note: (s) MUST have been savestring()'ed)
  114.  */
  115. #define setstrres(s) RES.val_Type = VTF_STRING, RES.val_Value.String = s
  116. #define setnumres(n) RES.val_Type = VTF_NUMBER, RES.val_Value.Number = n
  117.  
  118. #endif /* _COMMAND_H */
  119.